<?php
/**
 * A database query object
 *
 * Uses MySQLi PHP library (MySQL 4.1+)

 * @link http://webappkit.net
 * @package webappkit
 * @subpackage db
 * @author J.Ducastel <nospam0@ducastel.name>
 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
 */
interface iDbQuery {

    /**
     * Get the whole SQL query of the specified type
     *
     * @param  string $type select|count|insert|delete|update
     * @return string
     */
    public function getSql($type);

    /**
     * Adds a WHERE clause
     *
     * All clauses will be chained by AND
     *
     * @param  string $sql statement
     * @param  string $key optional, may be used to remove the clause
     * @return bool
     */
    public function addWhere($sql, $key = null);

    /**
     * Removes a named WHERE clause
     *
     * @param  string $key
     * @return bool
     */
    public function removeWhere($key);

    /**
     * Removes all WHERE clauses
     *
     * @return bool
     */
    public function flushWhere();

    /**
     * Gets the WHERE statement as SQL
     *
     * Ex. "hair='brown' AND feets=2"
     * Will be empty if there is no where clause
     *
     * @return string
     */
    public function getWhere();

    /**
     * Sets the ORDER BY statement
     *
     * @param  string $sql
     * @return bool
     */
    public function setOrder($sql);

    /**
     * Get back the ORDER BY statement
     *
     * @return string
     */
    public function getOrder();

    /**
     * Sets the LIMIT statement
     *
     * @param  string $sql
     * @return bool
     */
    public function setLimit($sql);

    /**
     * Gets the LIMIT statement
     *
     * @return string
     */
    public function getLimit();

    /**
     * Sets the SELECT part
     *
     * Ex. 'u.screen_name, u.email'
     *
     * @param  string $sql
     * @return bool
     */
    public function setSelect($sql);

    /**
     * Get back the SELECT part
     *
     * @return string
     */
    public function getSelect();

    /**
     * Sets the FROM part
     *
     * Ex. 'users AS u LEFT JOIN cars AS c ON c.user_id=u.id'
     *
     * @param  string $sql
     * @return bool
     */
    public function setFrom($sql);

    /**
     * Get back the FROM part
     *
     * @return string
     */
    public function getFrom();

    /**
     * Sets the COUNT sql part
     *
     * Ex. 'COUNT(*)'
     *
     * @param  string $sql
     * @return bool
     */
    public function setCount($sql);

    /**
     * Get back the COUNT part
     *
     * @return string
     */
    public function getCount();

    /**
     * Sets the INSERT part
     *
     * Ex. "users SET login='toto', password='secret'"
     *
     * @param  string $sql
     * @return bool
     */
    public function setInsert($sql);

    /**
     * Get back the INSERT part
     *
     * @return string
     */
    public function getInsert();
    
    /**
     * Sets the UPDATE part
     *
     * Ex. "users SET login='toto', password='secret'"
     *
     * @param  string $sql
     * @return bool
     */
    public function setUpdate($sql);

    /**
     * Get back the UPDATE part
     *
     * @return string
     */
    public function getUpdate();
}
